﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text;
using MixScript.DBService;
using MixScript.BLL;
namespace MixScript.BLL.SD
{
    public class cSalesOrder : cBaseBLL
    {
        public cSalesOrder()
        {
        }


        public bool getOutstandingSO(ref DataTable dt, string tgl1, string tgl2, string stblname, out string msg)
        {
            try
            {
                msg = "";
                string ssql = "select * from " + stblname + " where 1=1 and DVdt between '" + tgl1.ToString() + "' and '" + tgl2.ToString() + "' ";
                dt = Dbserver.ExecuteQuery(ssql, stblname);
                return dt.Rows.Count > 0;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public virtual bool getInquiryR(ref DataTable dt, string mat, string wr, string tgl1, string tgl2, string inqTable, out string msg)
        {
            try
            {
                msg = "";

                DataTable dts = new DataTable();
                string ssql = " SELECT  * FROM [dbo].[vw_joid_sales_return_v] AS a INNER JOIN " +
                             " [dbo].[vw_joid_sales_order_v] AS b ON a.cuod = b.cuod INNER JOIN " +
                             " [dbo].[vw_joid_customer_v] AS c ON b.cuid = c.codfbpid " +
                             " where 1=1  ";
                if (mat.Trim() != string.Empty)
                {
                    ssql += "and a.cuod='" + mat + "' ";
                }

                if (wr.Trim() != string.Empty)
                {
                    ssql += "and b.cuid='" + wr + "' ";
                }
                if ((tgl1.Trim() != string.Empty) && (tgl2.Trim() != string.Empty))
                {
                    ssql += "and b.oadt between '" + tgl1 + "' and '" + tgl2 + "'";
                }
                dt = Dbserver.ExecuteQuery(ssql, inqTable);
                return dt.Rows.Count > 0;
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return true;
        }  


        public virtual bool getInquiryS(ref DataTable dt, string mat, string wr, string tgl1, string tgl2, string inqTable, out string msg)
        {
            try
            {
                msg = "";
               
                DataTable dts = new DataTable();
                string ssql = "select * FROM [db_sgi].[dbo].[vw_joid_sales_order_v] where 1=1  ";
                if (mat.Trim() != string.Empty)
                {
                    ssql += "and cuod='" + mat + "' ";
                }

                if (wr.Trim() != string.Empty)
                {
                    ssql += "and cuid='" + wr + "' ";
                }
                if ((tgl1.Trim() != string.Empty) && (tgl2.Trim() != string.Empty))
                {
                    ssql += "and oadt between '" + tgl1 + "' and '" + tgl2 + "'";
                }
                dt = Dbserver.ExecuteQuery(ssql, inqTable);
                return dt.Rows.Count > 0;
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return true;
        }  

     


    }
}
